<!--
 * @Author: 黄达全
 * @Date: 2024-07-19 14:23:26
 * @LastEditTime: 2024-08-04 14:39:27
-->
<script lang="ts" setup>
import phoneForm from './components/phoneForm.vue';
import passwordForm from './components/passwordForm.vue';
import { getCurrentInstance, ComponentInternalInstance, ref } from "vue"
import type { Languages, Language,DEFAULT_CONFIG_TYPE,Tool } from "@/common/type"
import { useI18n } from "vue-i18n"

// 获取实例
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const tool = proxy?.$tool as Tool;
const config = proxy?.$config as DEFAULT_CONFIG_TYPE;

//  暗黑模式和语言设置的配置
const dark = ref<boolean>(tool.data.get("APP_DARK") || false);
const language = ref<string>(tool.data.get("APP_LANG") || config?.LANG)

// 切换暗黑模式
const configDark = () => {
    // 修改dark值
    dark.value = !dark.value;

    // 本地存储dark值
    if (dark.value) {
        document.documentElement.classList.add("dark")
        tool.data.set("APP_DARK", dark.value);
    } else {
        document.documentElement.classList.remove("dark")
        tool.data.remove("APP_DARK");
    }
}

// 语言列表
const languages = ref<Languages>([
    {
        name: '简体中文',
        value: 'zh-cn',
    },
    {
        name: 'English',
        value: 'en',
    }
])

const { locale } = useI18n();
// 切换语言
const configLang = (command: Language) => {
    // 修改语言
    language.value = command.value

    // 修改i18n配置
    locale.value = command.value

    // 本地存储语言
    tool.data.set("APP_LANG", command.value);
}
</script>

<template>
    <div class="login_bg">
        <!-- 左侧 -->
        <div class="login_adv" style="background-image: url(img/auth_banner.jpg);">
            <!-- 标题 -->
            <div class="login_adv__title">
                <h2>{{ $t('login.title') }}</h2>
                <h4>{{ $t('login.slogan') }}</h4>
                <p>{{ $t('login.describe') }}</p>
            </div>

            <!-- 背景蒙层 -->
            <div class="login_adv__mask"></div>
            <!-- 底部版权 -->
            <div class="login_adv__bottom">
                &copy; {{ $t("login.title") }} {{ $config.APP_VER }}
            </div>
        </div>


        <!-- 右侧 -->
        <div class="login_main">
            <!-- 暗黑模式和语言设置 -->
            <div class="login_config">
                <!-- 暗黑模式 -->
                <el-button :icon="dark ? 'el-icon-sunny' : 'el-icon-moon'" circle type="info" @click="configDark"
                    style="margin-right: 15px;"></el-button>
                <!-- 语言设置  -->
                <el-dropdown trigger="click" placement="bottom-end" @command="configLang">
                    <el-button circle>
                        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                            aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet"
                            viewBox="0 0 512 512">
                            <path
                                d="M478.33 433.6l-90-218a22 22 0 0 0-40.67 0l-90 218a22 22 0 1 0 40.67 16.79L316.66 406h102.67l18.33 44.39A22 22 0 0 0 458 464a22 22 0 0 0 20.32-30.4zM334.83 362L368 281.65L401.17 362z"
                                fill="currentColor"></path>
                            <path
                                d="M267.84 342.92a22 22 0 0 0-4.89-30.7c-.2-.15-15-11.13-36.49-34.73c39.65-53.68 62.11-114.75 71.27-143.49H330a22 22 0 0 0 0-44H214V70a22 22 0 0 0-44 0v20H54a22 22 0 0 0 0 44h197.25c-9.52 26.95-27.05 69.5-53.79 108.36c-31.41-41.68-43.08-68.65-43.17-68.87a22 22 0 0 0-40.58 17c.58 1.38 14.55 34.23 52.86 83.93c.92 1.19 1.83 2.35 2.74 3.51c-39.24 44.35-77.74 71.86-93.85 80.74a22 22 0 1 0 21.07 38.63c2.16-1.18 48.6-26.89 101.63-85.59c22.52 24.08 38 35.44 38.93 36.1a22 22 0 0 0 30.75-4.9z"
                                fill="currentColor"></path>
                        </svg>
                    </el-button>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item v-for="item in languages" :key="item.value" :command="item"
                                :class="{ 'selected': language == item.value }">{{ item.name }}</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>

            <!-- 登录注册 -->
            <div class="login_form">
                <div class="login_header">
                    <div class="logo">
                        <img src="/img/logo.png" />
                        <label>{{ $t('login.title') }}</label>
                    </div>
                </div>

                <el-tabs>
                    <el-tab-pane :label="$t('login.accountLogin')" lazy>
                        <password-form></password-form>
                    </el-tab-pane>
                    <el-tab-pane :label="$t('login.mobileLogin')" lazy>
                        <phone-form></phone-form>
                    </el-tab-pane>
                </el-tabs>

            </div>
        </div>
    </div>
</template>

<style lang="scss" scoped>
// 背景
.login_bg {
    width: 100%;
    height: 100%;
    background: #fff;
    display: flex;

    // 左侧
    .login_adv {
        width: 33.33333%;
        background-color: #555;
        background-size: cover;
        background-position: center center;
        background-repeat: no-repeat;
        position: relative;

        // 标题样式
        .login_adv__title {
            color: #fff;
            padding: 40px;
            position: absolute;
            top: 0px;
            left: 0px;
            right: 0px;
            z-index: 2;

            h2 {
                font-size: 40px;
            }

            h4 {
                font-size: 18px;
                margin-top: 10px;
                font-weight: normal;
            }

            p {
                font-size: 14px;
                margin-top: 10px;
                line-height: 1.8;
                color: rgba(255, 255, 255, 0.6);
            }

            div {
                margin-top: 10px;
                display: flex;
                align-items: center;

                span {
                    margin-right: 15px;
                }

                i {
                    font-size: 40px;

                    &.add {
                        font-size: 20px;
                        color: rgba(255, 255, 255, 0.6);
                    }
                }
            }
        }

        // 底部版权
        .login_adv__bottom {
            position: absolute;
            left: 0px;
            right: 0px;
            bottom: 0px;
            color: #fff;
            padding: 40px;
            background-image: linear-gradient(transparent, #000);
            z-index: 3;
            display: flex;
            align-items: center;

        }

        // 背景蒙层
        .login_adv__mask {
            position: absolute;
            top: 0px;
            left: 0px;
            right: 0px;
            bottom: 0px;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1;
        }
    }

    // 右侧
    .login_main {
        flex: 1;
        overflow: auto;
        display: flex;

        .login_config {
            position: absolute;
            top: 20px;
            right: 20px;
        }

        .login_form {
            width: 400px;
            margin: auto;
            padding: 20px 0;

            .login_header {
                margin-bottom: 40px;

                .logo {
                    display: flex;
                    align-items: center;

                    img {
                        width: 40px;
                        height: 40px;
                        vertical-align: bottom;
                        margin-right: 10px;
                    }

                    label {
                        font-size: 26px;
                        font-weight: bold;
                    }
                }
            }

            :deep(.el-tabs) .el-tabs__header {
                margin-bottom: 25px;

                .el-tabs__item {
                    font-size: 14px;
                }
            }
        }
    }
}


@media (max-width: 1200px) {
    .login-form {
        width: 340px;
    }
}

@media (max-width: 1000px) {
    .login_main {
        display: block;
    }

    .login_main .login_config {
        position: static;
        padding: 20px 20px 0 20px;
        text-align: right;
    }

    .login-form {
        width: 100%;
        padding: 20px 40px;
    }

    .login_adv {
        display: none;
    }
}
</style>
